﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using Jumpton.Data;

namespace Jumpton.SFA.Server.BusinessRule
{
    public class ReportData : BusinessLogic
    {
        /// <summary>
        /// 查询销售代表拜访率
        /// </summary>
        /// <param name="Domain_ID">域ID</param>
        /// <param name="Start_Date">开始时间</param>
        /// <param name="End_Date">结束时间</param>
        /// <param name="Users_ID">管辖用户ID</param>
        /// <returns></returns>
        public DataSet getSalesReachedRate(decimal Domain_ID, string Start_Date, string End_Date, string Users_ID)
        {
            try
            {
                DataSet ds = new DataSet();
                SqlParameter[] para = { new SqlParameter("@DOMAIN_ID", SqlDbType.Decimal, 10),
                                      new SqlParameter("@START_TIME", SqlDbType.VarChar, 50),
                                      new SqlParameter("@END_TIME", SqlDbType.VarChar, 50),
                                      new SqlParameter("@USERS_ID", SqlDbType.VarChar, 500)};
                para[0].Value = Domain_ID;
                para[1].Value = Start_Date;
                para[2].Value = End_Date;
                para[3].Value = Users_ID;

                ds = SQLHelper.RunProcedure("SP_SALES_REACHED_RATE", para, "rows");
                return ds;
            }
            catch
            {
                return null;
            }
        }

        public DataSet getSalesReachedRate(decimal Domain_ID, string Start_Date, string End_Date, string Users_ID, string ShowType)
        {
            try
            {
                DataSet ds = new DataSet();
                SqlParameter[] para = { new SqlParameter("@DOMAIN_ID", SqlDbType.Decimal, 10),
                                      new SqlParameter("@START_TIME", SqlDbType.VarChar, 50),
                                      new SqlParameter("@END_TIME", SqlDbType.VarChar, 50),
                                      new SqlParameter("@USERS_ID", SqlDbType.VarChar, 500),
                                      new SqlParameter("@SHOWTYPE", SqlDbType.VarChar, 50)};
                para[0].Value = Domain_ID;
                para[1].Value = Start_Date;
                para[2].Value = End_Date;
                para[3].Value = Users_ID;
                para[4].Value = ShowType;

                ds = SQLHelper.RunProcedure("SP_SALES_REACHED_RATE_DATE", para, "rows");
                return ds;
            }
            catch
            {
                return null;
            }
        }

        /// <summary>
        /// 查询销售代表拜访达成率
        /// </summary>
        /// <param name="Domain_ID">域ID</param>
        /// <param name="Start_Date">开始时间</param>
        /// <param name="End_Date">结束时间</param>
        /// <param name="Users_ID">管辖用户ID</param>
        /// <returns></returns>
        public DataSet getSalesAchievementRates(decimal Domain_ID, string Start_Date, string End_Date, string Users_ID, string ShowType)
        {
            try
            {
                DataSet ds = new DataSet();
                SqlParameter[] para = { new SqlParameter("@DOMAIN_ID", SqlDbType.Decimal, 10),
                                      new SqlParameter("@START_TIME", SqlDbType.VarChar, 50),
                                      new SqlParameter("@END_TIME", SqlDbType.VarChar, 50),
                                      new SqlParameter("@USERS_ID", SqlDbType.VarChar, 500),
                                      new SqlParameter("@SHOWTYPE", SqlDbType.VarChar, 50)};
                para[0].Value = Domain_ID;
                para[1].Value = Start_Date;
                para[2].Value = End_Date;
                para[3].Value = Users_ID;
                para[4].Value = ShowType;

                ds = SQLHelper.RunProcedure("SP_SALES_ACHIEVEMENT_RATES", para, "rows");
                return ds;
            }
            catch
            {
                return null;
            }
        }

        /// <summary>
        /// 查询销售代表业绩
        /// </summary>
        /// <param name="Domain_ID">域ID</param>
        /// <param name="Start_Date">开始时间</param>
        /// <param name="End_Date">结束时间</param>
        /// <param name="Users_ID">管辖用户ID</param>
        /// <returns></returns>
        public DataSet getSalesOrdersRates(decimal Domain_ID, string ShowType)
        {
            try
            {
                DataSet ds = new DataSet();
                SqlParameter[] para = { new SqlParameter("@DOMAIN_ID", SqlDbType.Decimal, 10),
                                      new SqlParameter("@SHOWTYPE", SqlDbType.VarChar, 50)};
                para[0].Value = Domain_ID;
                para[1].Value = ShowType;

                ds = SQLHelper.RunProcedure("SP_SALES_ORDERS", para, "rows");
                return ds;
            }
            catch
            {
                return null;
            }
        }

        /// <summary>
        /// 查询销售代表拜访执行情况
        /// </summary>
        /// <param name="Domain_ID">域ID</param>
        /// <param name="Start_Date">开始时间</param>
        /// <param name="End_Date">结束时间</param>
        /// <param name="Users_ID">管辖用户ID</param>
        /// <returns></returns>
        public DataSet getVisitExecution(decimal Domain_ID, DateTime Start_Date, DateTime End_Date, string Users_ID)
        {
            try
            {
                DataSet ds = new DataSet();

                ds = SqlData.OpenSP("SP_WelcomePage_EXECUTION", Domain_ID, Users_ID, Start_Date, End_Date);
                return ds;
            }
            catch
            {
                return null;
            }
        }

        /// <summary>
        /// 查询销售代表个人业绩情况
        /// </summary>
        /// <param name="Domain_ID">域ID</param>
        /// <param name="Start_Date">开始时间</param>
        /// <returns></returns>
        public DataSet getSalesPerformance(decimal Domain_ID, string Users_ID)
        {
            try
            {
                DataSet ds = new DataSet();

                ds = SqlData.OpenSP("SP_WelcomePage_Performance", Domain_ID, Users_ID);
                return ds;
            }
            catch
            {
                return null;
            }
        }

        /// <summary>
        /// 查询促销人员活动信息
        /// </summary>
        /// <param name="startime">开始时间</param>
        /// <param name="endtime">结束时间</param>
        /// <param name="domainID">域ID</param>
        /// <param name="brandCode"></param>
        /// <returns></returns>
        public DataSet getPromotions(string startime, string endtime, string domainID, string brandCode)
        {
            try
            {
                DataSet ds = new DataSet();
                ds = SqlData.OpenSP("SP_PROMOTION_PERSON_REPORT", startime, endtime, domainID, brandCode);
                return ds;
            }
            catch
            {
                return null;
            }
        }
    }
}
